package com.im.partchat.ui.activity.more;

import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;

import com.im.partchat.App;
import com.im.partchat.R;
import com.im.partchat.base.BaseActivity;
import com.im.partchat.mvp.persenter.ChangePasswordPersenter;
import com.im.partchat.utils.AppManager;
import com.im.partchat.utils.Navigation;

import butterknife.BindView;
import butterknife.OnClick;

public class ChangePasswordActivity extends BaseActivity {

    @BindView(R.id.old_password)
    EditText oldPassword;
    @BindView(R.id.new_password)
    EditText newPassword;
    @BindView(R.id.re_password)
    EditText rePassword;
    @BindView(R.id.btn_ok)
    Button btnOk;
    private ChangePasswordPersenter changePasswordPersenter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_change_password;
    }

    @Override
    protected void initData() {
        changePasswordPersenter = new ChangePasswordPersenter(this, this);
    }

    @Override
    public void onLoadDataSuccess(Object o, String flag) {
        showToast("密码修改成功，请重新登陆");
        App.setUserBean(null);
        Navigation.navigateLogin();
        AppManager.getAppManager().finishAllActivity();

    }


    @OnClick(R.id.btn_ok)
    public void onViewClicked() {

        String moldPassword = oldPassword.getText().toString();
        String mNewPassword = newPassword.getText().toString();
        String mRePassword = rePassword.getText().toString();
        if (TextUtils.isEmpty(moldPassword)) {
            showToast("旧密码不能为空");
            return;
        }
        if (TextUtils.isEmpty(mNewPassword)) {
            showToast("新码不能为空");
            return;
        }
        if (!mNewPassword.equals(mRePassword)) {
            showToast("两次密码输入不一致");
            return;
        }
        changePasswordPersenter.getMainData(App.getUserBean().getId(), moldPassword, mNewPassword);
    }
}
